namespace SharpTalk.Core
{
    using System;
    using System.Linq;
    using Base;
    using System.Runtime.Serialization;

    [DataContract]
    [Serializable]
    public sealed class User : UserBase, IEquatable<User>, ICloneable
    {
        /// <summary>
        /// Create a new instance of the <see cref="T:SharpTalk.Core.User"/> class.
        /// </summary>
        public User() 
        {
        }
        /// <summary>
        /// Create a new instance of the <see cref="T:SharpTalk.Core.Base.UserBase"/> class.
        /// </summary>
        /// <param name="guid">User guid</param>
        internal User(Guid guid) 
            : base(guid)
        {
        }
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool Equals(User other)
        {
            return base.Equals(other);
        }
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>. </param><filterpriority>2</filterpriority>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return Equals(obj as User);
        }
        /// <summary>
        /// Serves as a hash function for a particular type. 
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:SharpTalk.Core.Base.UserBase"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public object Clone()
        {
            var clone = new User(this.Guid)
                            {
                                FirstName = this.FirstName,
                                LastName = this.LastName,
                                NickName = this.NickName,
                                Image = this.Image,
                                Status = this.Status,
                                CustomStatus = this.CustomStatus
                            };
            return clone;
        }

        public static bool operator ==(User left, User right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(User left, User right)
        {
            return !Equals(left, right);
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override string ToString()
        {
            return String.Format("{0} ({1:N})",FullName, Guid);
        }

#if DEBUG
        public string FullProperties()
        {
            var sb = new System.Text.StringBuilder();
            foreach (var property in this.GetType().GetProperties().Where(property => property.CanRead))
                sb.AppendLine(String.Format("{0} : {1}", property.Name, property.GetValue(this, null)));
            return sb.ToString();
        }
#endif
       
    }
}